package br.com.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.constraints.NotEmpty;

import br.com.anotations.Label;

@Entity
@Table(name="tb_pessoa")
public class Pessoa extends Domain {
	
	private static final long serialVersionUID = 1L;

	
	/**************************************************************************/
	/**                             ATRIBUTOS                                **/
	/**************************************************************************/

	public Pessoa(){
		this.sexo= new Sexo();
	}
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY) 
	@Column(name="idPessoa")
	private Integer id;
	
	@NotEmpty
	@Column (name="nome", length=100)
	private String nome;
	
	
	@Temporal(TemporalType.DATE)
	@Column(name = "dataNascimento")
	@Label(value="Data Nascimento")
	private Date dataNascimento;
	
	
   
    /********************************************************************/
	/**                       RELACIONAMENTOS         				   **/
	/********************************************************************/
	@JoinColumn (name = "idSexo")
	@ManyToOne  (fetch = FetchType.EAGER)
	private Sexo sexo;
   
    
    /********************************************************************/
	/**                           TRANSIENTS        				   **/
	/********************************************************************/
	
	
	/********************************************************************/
	/**                          GET's E SET's                         **/
	/********************************************************************/
	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Date getDataNascimento() {
		return dataNascimento;
	}

	public void setDataNascimento(Date dataNascimento) {
		this.dataNascimento = dataNascimento;
	}

	public Sexo getSexo() {
		return sexo;
	}

	public void setSexo(Sexo sexo) {
		this.sexo = sexo;
	}

	

	/********************************************************************/
	/**                EQUALS E HASH CODE  - RETIRAR LIST's            **/
	/********************************************************************/
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		result = prime * result + ((sexo == null) ? 0 : sexo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pessoa other = (Pessoa) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		if (sexo == null) {
			if (other.sexo != null)
				return false;
		} else if (!sexo.equals(other.sexo))
			return false;
		return true;
	}

	


	
	
	
}
